our $tColByName_initialized;  # true after the first time through
our @tColByName_columns;
if (! $tColByName_initialized) {
	$tColByName_initialized = 1;
	print "Filter columns by name.\n";
	my $desc;
	eval '$desc = \%desc_' . $current_component;
	my @names;
	foreach (@{$desc->{'schema'}}) {
		push @names, $_->{'name'};
	}
	$" = ", ";
	print "Names to match:\n", "@names", "\n";
	my @input_names = split /\t/, $input_row[0];
	foreach (@input_names) {
		s/^\s*//;  # strip leading white space
		s/\s*$//;  # and trailing white space
		s/\W/_/g;  # replace anything other than alphanumeric or _
	}
	print "Input names:\n";
	print "@input_names", "\n";
	tColByName_name: for (my $name = 0; $name < @names; $name++) {
		for (my $column = 0; $column < @input_names; $column++) {
			if (lc $input_names[$column] eq lc $names[$name]) {  # case insensitive
				$tColByName_columns[$name] = $column;
				next tColByName_name;
			}
		}
		print "WARNING: schema element \"" . $names[$name] . "\" not found!\n";
	}
	print "Mapping: @tColByName_columns\n";
} else {
	# split and clean input line
	my @values = split /\t/, $input_row[0];
	foreach (@values) {
		s/^\s*//;  # strip leading white space
		s/\s*$//;  # and trailing white space
	}
	# map to output fields
	for (my $field = 0; $field < @tColByName_columns; $field++) {
		print $field, " --> ", $values[$tColByName_columns[$field]], "\n";
		$output_row[$field] = $values[$tColByName_columns[$field]];
	}
}

# code samples:
#
# # copy the whole line
# @output_row = @input_row;
#
# # multiply by 2 the row identifier
# $output_row[id] = $input_row[id] * 2;
#
# # lowercase the name
# $output_row[name] = lc $input_row[name];
